<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box"> 
        <h2>鼠标移入改变样式，鼠标移出恢复。</h2>
    </div>
</body>
<script>
    let box = document.querySelector("#box")
    box.onmouseover = function(){
        box.className = "hover"
    }
    box.onmouseout  =function(){
        box.className  = ""
    }
</script>
<style>
    body{
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    #box{
        width: 300px;
        height: 300px;
        background-color: black;
        color: #fff;
    }
    h2{
        margin: 30px;
    }
    #box.hover{
        color:red;
        background:#f0f0f0;
        border:20px solid red;
    }
</style>
</html>